<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>各网点领卡登记</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${pageContext.request.contextPath }/scripts/boot.js"
	type="text/javascript"></script>
<style type="text/css">
<!--
#Layer1 {
	position: absolute;
	left: 20%;
	top: 94px;
	width: 729px;
	height: 325px;
	z-index: 1;
}
-->
</style>
</head>
<body>
	<div id="Layer1">
		<div style="width:100%;" align="center">
			<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
				<table style="width:100%;">
					<tr>
						<td style="width:100%;text-align:center;"><font face="宋体"><strong>各网点领卡登记</strong>
						</font>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<div>
			<form id="form1" method="post">
				<table style="width:100%;border:solid 1px #aaa;width:100%;"
					height="238">
					<tr>
						<td width="9%" style="white-space:nowrap;">制卡批次</td>
						<td colspan="2"><input name="aaz001" width="100%"
							class="mini-textbox" emptyText="请输入制卡批次" onenter="enter" />
						</td>
						<td width="55%" rowspan="6">
							<div class="mini-fit">
								<div id="datagrid1" class="mini-datagrid"
									style="width:100%;height:97%;" allowResize="true" url=""
									idField="id" ondrawsummarycell="onDrawSummaryCell"
									multiSelect="true" allowCellEdit="true" allowCellSelect="true"
									multiSelect="true" showPager="false">
									<div property="columns">
										 <div type="checkcolumn" ></div>  
										<div field="aae0081" headerAlign="center">银行</div>
										<div field="aae008" headerAlign="center" visible="false">银行</div>
										<div field="lksl" summaryType="sum" headerAlign="center">领卡数量</div>
									</div>
								</div>
							</div></td>
					</tr>
					<tr>
						<td style="white-space:nowrap;">网点名称</td>
						<td colspan="2"><input name="aaz730" class="mini-combobox"
							style="width:100%;" textField="mch" valueField="bm"
							emptyText="请选择..." required="true"
							onvaluechanged="onvaluechanged"
							url="${pageContext.request.contextPath }/BK.do?method=getSelectqh" />
						</td>
					</tr>
					<tr>
						<td style="white-space:nowrap;">领卡类型</td>
						<td colspan="2"><input name="lklx" width="100%"
							class="mini-combobox" valueField="id" textField="text" id="lklx"
							emptyText="请选择领卡类型"
							data="[{id:1,text:'正常领卡'}, {id:2, text: '未成功制卡补卡'}, {id:3, text: '卡厂回卡质量问题补卡'}]"
							onvalidation="onvaluechanged1" /></td>
					</tr>
					<tr>
						<td style="white-space:nowrap;">领卡网点</td>
						<td colspan="2"><input name="aaz7301" class="mini-combobox"
							style="width:100%;" textField="mch" valueField="bm"
							emptyText="请选择..." required="true"
							url="${pageContext.request.contextPath }/BK.do?method=getSelectqh" />
						</td>
					</tr>
					<tr>
						<td style="white-space:nowrap;">领卡时间</td>
						<td colspan="2"><input name="aaz729" width="100%"
							class="mini-datepicker" inputStyle="background:rgb(241,241,243)"
							allowInput="false" />
						</td>
					</tr>
					<tr>
						<td style="white-space:nowrap;">领卡人</td>
						<td width="16%"><input name="aae011" width="100%"
							class="mini-textbox" emptyText="请输入领卡人工号" />
						</td>
						<td width="16%"><input name="aae0111" width="100%"
							class="mini-textbox" inputStyle="background:rgb(241,241,243)"
							allowInput="false" readonly="true" />
						</td>
					</tr>
					<tr>
						<td colspan="4" scope="row" align="center"><a
							class="mini-button" iconCls="icon-ok" onclick="onOk" 
							plain="false">确认</a> <a class="mini-button" iconCls="icon-remove" 
							onclick="onCancel" plain="false">重置</a>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		mini.parse();
		var grid = mini.get("datagrid1");
		var form = new mini.Form("form1");
		window.onload = function() {
			var today = new Date();
			mini.getbyName("aaz729").setValue(today);
		};
		var ss = false;
		function enter() {
			ss = false;
			var aaz001 = mini.getbyName("aaz001").getValue();
			grid.setUrl("${pageContext.request.contextPath }/AZ20.do?method=getbank&aaz001="
							+ aaz001);
			grid.reload();
		}
		function onCancel() {
		ss=false;
			form.clear();
			grid.clearRows();
			var today = new Date();
			mini.getbyName("aaz729").setValue(today);
		}
		function onvaluechanged1() {
			var aaz001 = mini.getbyName("aaz001").getValue();
			var lklx = mini.getbyName("lklx").getValue();
			var aaz730 = mini.getbyName("aaz730").getValue();
			if(aaz001==""){
			mini.alert("请输入制卡批次！");
			return;
			}
			if(aaz730==""){
			mini.alert("请选择网点名称！");
			return;
			}
			/* $.ajax({
			     url: "${pageContext.request.contextPath }/AZ20.do?method=getlksl",
				type: 'post',
			     data: { aaz001: aaz001,lklx:lklx,aaz730:aaz730},
			     cache: false,
			     success: function (text) {
			           var grid=mini.get("datagrid1");
			           
			     },
			     error: function (jqXHR, textStatus, errorThrown) {
			         alert(jqXHR.responseText);
			         CloseWindow();
			     }
			 }); */
			grid.setUrl("${pageContext.request.contextPath }/AZ20.do?method=getlksl1&aaz001="
							+ aaz001 + "&lklx=" + lklx + "&aaz730=" + aaz730);
			grid.reload();
			ss = true;
		}
		function onDrawSummaryCell(e) {
			var result = e.result;
			var grid = e.sender;
			//服务端汇总计算
			if (ss == true) {
				if (e.field == "lksl") {
					if (e.cellHtml == "0") {
						mini.alert("没有可发放的卡！");
					}
				}
			}
		}
		grid.on("cellbeginedit", function(e) {
			var record = e.record;
			if (record.lksl == "0") {
				e.cancel = true;
			}
		});
		grid.on("beforeselect", function(e) {
			var record = e.record;
			if (record.lksl == "0") {
				e.cancel = true;
			}
		});
		function onvaluechanged() {
		    ss=false;
			mini.getbyName("lklx").setValue("");
			mini.getbyName("aaz7301").setValue("");
			mini.getbyName("aae011").setValue("");
			grid.clearRows();
		}
		function onOk(){
		    var aaz001 = mini.getbyName("aaz001").getValue();
			var lklx = mini.getbyName("lklx").getValue();
			var aaz730 = mini.getbyName("aaz730").getValue();
			var aaz7301 = mini.getbyName("aaz7301").getValue();
			var aae011 = mini.getbyName("aae011").getValue();
			if(aaz730!=aaz7301){
			mini.alert("领卡网点和网点名称不一致！");
			return;
			}
			if(aaz001==""){
			mini.alert("请输入制卡批次！");
			return;
			}
			if(aaz730==""){
			mini.alert("请选择网点名称！");
			return;
			}
			if(lklx==""){
			mini.alert("请选择领卡类型！");
			return;
			}
			if(aaz7301==""){
			mini.alert("请选择领卡网点！");
			return;
			}
			if(aae011==""){
			mini.alert("请输入领卡人！");
			return;
			}
			var rows=grid.getSelecteds();
			/* alert(rows.length);
			alert(mini.encode(rows)); */
			if(rows.length==0){
			mini.alert("请选择领取的银行！");
			return;
			}
			var ids = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                  var r = rows[i];
                  ids.push(r.aae008);
            }
            var id = ids.join(',');
			$.ajax({
			     url: "${pageContext.request.contextPath }/AZ20.do?method=setlkdj",
				type: 'post',
			     data: { aaz001: aaz001,lklx:lklx,aaz730:aaz730,aaz7301:aaz7301,aae011:aae011,id:id},
			     cache: false,
			     success: function (text) {
			           mini.alert(text);
			           onCancel();
			     },
			     error: function (jqXHR, textStatus, errorThrown) {
			         mini.alert(jqXHR.responseText);
			         CloseWindow();
			     }
			 });
		}
	</script>
</body>
</html>